<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	
	<c:if test="${User.type eq '2'  }">
		<style type="text/css">
			.ibox-content{text-align: left;}
		</style>
	</c:if>
</head>
<body>
<!-- 顶部导航开始 -->
	<c:if test="${User.type eq '2'  }">
		<%@include file="/WEB-INF/common/header.jsp"%>
	</c:if>
	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" >
        <div class="row" id="test01">
            <div>
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5></h5>
                    </div>
                    <div class="ibox-content">
                        <form action="${path}/city/query" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label for="ti" class="sr-only">城市名称</label>
                                <input type="text" placeholder="城市名称"  name="title" id="ti" class="form-control">
                            </div>

                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-reset" class="btn btn-warning">重置</button>
                            <button type="button" id="btn-add" class="btn btn-success fr">添加</button>
                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
            	url : "${path}/city/query",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                   	id: "id", //相当于设置主键
		           	root: "result",//Json数据
		           	total: "allPage",//总页数
					page: "page", //当前页
					records: "allCount",//总记录数
					repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 30],
                colNames: ['城市名称','添加时间', '操作'],
                colModel: [{
                        name: 'name',
                        index: 'name',
                        width: 20
                    },{
                        name: 'createDate',
                        index: 'createDate',
                        width: 30
                    },{
                        name: 'operator',
                        index: 'operator',
                        width: 45,
                        formatter:function(cellvalue, options, rowObject){

                        	var html = "";
                        	html += "<a class='btn btn-danger btn-xs' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"del('"+rowObject.id+"')\">删除</a>";
                            return html;
                        }
                    }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: true
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");

            $("#btn-add").click(function(){
                layer.open({
                    type: 2,
                    title: '添加城市',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['70%', '80%'],
                    content: '${path}/city/add' //iframe的url
                });

                <%--window.location.href='${path}/city/add';--%>
            });
            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/city/query",
                    datatype:'json',
                    postData : {
                    	"name":$("#ti").val(),
                    },
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
            
        });


        function  del(id){
        		$.ajax({
                    type: "POST",
                    url: "${path}/city/del",
                    data:{"id":id},
                    dataType: "json",
                    success: function(json){
                        if(json.code == 0){
                        	alert(json.msg);
                        	window.location.reload();
                        }else{
                        	layer.msg(json.msg);
                        }
                    }
                });
        }

        function det(id) {
            window.location.href='${path}/article/details?id='+id;
        }


    </script>
</body>
</html>
